signuperrortag	= true;

function checkemailsignup()
{
	return JS_CheckEmail($('#email').val(),oktip($('#email')),errortipsignup($('#email')),'register');
}
function checkpasswordsignup()
{
	return JS_CheckPassword($('#password').val(),oktip($('#password')),errortipsignup($('#password')));
}
function checknickname()
{
	return JS_CheckNickname($('#username').val(),oktip($('#username')),errortipsignup($('#username')));
}
function checkcodes()
{
	if($('#captcha').length > 0 && $("#captcha").val().length == 8)
	{

		hidedesc($('#captcha'));
		return true;
	}
	else
	{
		showdesc($('#captcha'));
		signuperrortag	= false;
		return false;
	}
}
function checkdoublepassword()
{
	if(checkpasswordsignup()&&$('#password').val()==$('#confirm_password').val())
	{
		oktip($('#confirm_password'))();
		return true;
	}
	else
	{
		if($('#confirm_password').val() == '')
		{
			errortipsignup($('#confirm_password'))('请输入确认密码');
			return false;
		}
		else
		{
			errortipsignup($('#confirm_password'))('两次密码输入不一致，请重新输入');
			return false;
		}
	}
}
function errortipsignup(obj)
{
	var text	= '发生错误';
	return function ()
	{
		if(arguments[0]!=undefined&&arguments[0]!='')
		{
			text	= arguments[0];
		}
		obj.parents('.iput').next().html(text).addClass('lowrong').addClass('mll').removeClass('loright').removeClass('mtl15');
		signuperrortag	= false;
	}
}
function oktip(obj)
{
	return function ()
	{
		obj.parents('.iput').next().html(' ').addClass('loright').addClass('mtl15').removeClass('lowrong').removeClass('mll');
	}
}
function signup()
{
	    function success()
	    {
	    	var urlreferer = $("#urlreferer").val();
		    if(urlreferer)
		    {
			    urlreferer = urlreferer;
		    }else
		    {
			    urlreferer = "/";
		    }
	    	var mails = $('#email').val().split("@");
			var mailurl = 'http://mail.'+mails[1]+'';
			signupdialog('注册成功！<br/><br/>请到邮箱收取激活邮件,并点击其中的激活链接激活账号！<br/><br/><a href="'+ mailurl +'" class="btncd mrs" target="_blank">登录邮箱</a> <a href="'+ urlreferer +'" class="btnsc mrs">返回</a>');
	    }
	    function error(msg)
	    {
		    if (msg == 'ERR'){
			    msg	= "注册失败，要按提示填写哦~"
		    }
		    showerrorinfo("注册失败", msg);
		    return false;
	    }

	    signuperrortag = true;
	    checkemailsignup();checkpasswordsignup();checknickname();checkdoublepassword();
	    checkcode();
	    if(signuperrortag)
	    {
		    JS_Signup($('#email').val(),$('#password').val(),$('#username').val(),$('#captcha').val(),success,error);
	    }
	    return false;
}
function showdesc(obj)
{
	obj	= $(obj);
	obj.parents('.itm').next().css({'visibility':'visible'});
}
function hidedesc(obj)
{
	obj	= $(obj);
	obj.parents('.itm').next().css({'visibility':'hidden'});
}
/**
 * @time: 2012-07-05
 * 
 * @desc: 弹出注册信息框
 * @author: jack
**/
function signupdialog(msg)
{
    var h = $(window).height() / 2 - 150;
    var w = $(window).width() / 2 - 290;
    var id = 'signupdialogindex';
    var html = '<div id="'+ id +'" class="dlceng r5" style="z-index: 9999; top: '+ h +'px; left: '+ w +'px; position: fixed; display: block; ">'
            html += '<div class="dlccontent" id="deng">'
                html += '<a href="javascript:void(0);" class="scengb dlclose"></a>'        
                html += '<div class="tith">'
                    html += '<h3>注册成功</h3>'                
                html += '</div>'
                html += '<div style="padding: 50px;font-size:14px;">'+ msg +'</div>' 
            html += '</div>'
        html += '</div>'
    $('body').append(html);
    $("#"+id).dialog({
        resizable:false,
        draggable:false,
        modal:true
    });
    window.api.showtype='current';
    $(".dlclose").live("click",function(){
        $("#"+id).remove();
        window.api.showtype='newwindow';
        $("#"+id).dialog("close");
    });
}
